$(document).ready(function(){
    mzget({
        url:pub_change_mone,
        success:function(res){
            if(res.code == '2000'){
            
                if(res.msg && res.msg.wx_img){
                    $('#wxqrcode').attr('src',res.msg.wx_img);
                    $('.subcontent').removeClass('mui-hidden');
                }
                if(res.msg && res.msg.is_wx == 0){
                    $('.detailcontent').removeClass('mui-hidden');
                }


            }else{
                mui.toast(res.msg);
            }
        },
        error:function(){

        }
    })

    $('#yzm').click(function(){
        var phone = $('#phone').val();
        if(phone.length != 11){
            mui.toast('输入正确的手机号');
            return;
        }
        mzpost({
            url:pub_yzm,
            data:{phone:phone},
            success:function(res){
                if(res.status == 'true' || res.status == true){
                    $('#yzm').hide();
                    mui.toast('获取成功');
                    var code = res.msg.code;
                    $('#vcode').val(code);
                }else{
                    mui.toast(res.msg);
                }
            },
            error:function(err){
                mui.toast('错误');
            }
        })
    })




    $('#addimgbtn').click(function(){
        $('#qrcodeimg').click()
    })

    $('#qrcodeimg').change(function(){
        var file = document.getElementById('qrcodeimg').files[0];
        mui.toast(file.name)

        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onerror = function(){
            mui.toast('加载失败')
        };
        reader.onload = function(){
            
            $('#addimgbtn').attr('src',reader.result)
        };

    })

})

function uploadimg(){
    var phone = $('#phone').val();
    if(phone.length != 11){
        mui.toast('输入正确的手机号');
        return;
    }
    if($('#vcode').val().length == 0){
        mui.toast('请输入验证码');
        return;
    }
    var params = new FormData(document.forms[0]);
    mzpost({
        url:pub_change_mone,
        processData: false,
        contentType: false,
        data:params,
        success:function(res){
            if(res.code == '2000'){
                mui.toast(res.msg);
                location.reload()
            }else{
                mui.toast(res.msg);
            }
        },
        error:function(err){
            mui.toast('上传错误');
        }
    })
}